package org.softmed.ATComm.swingClient;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;

public class Client extends JFrame {

	JToolBar toolbar = new JToolBar(null, JToolBar.HORIZONTAL);
	URLPanel url = new URLPanel();
	SerialPortPanel serial = new SerialPortPanel();
	SMSPanel sms = new SMSPanel();
	StatusPanel status = new StatusPanel();

	int width = 512;
	int height = 240;
	private DevToolBar bar;

	ClientManager clientManager = new ClientManager(this);

	public Client() {
		super(
				"ATComm SWING Client - by Guilherme Gomes - guilhermegrg@gmail.com");

		Container container = getContentPane();
		container.setLayout(new BorderLayout());

		JPanel center = new JPanel();
		center.setLayout(new BoxLayout(center, BoxLayout.PAGE_AXIS));
		center.add(url);
		center.add(serial);
		center.add(sms);

		center.setMaximumSize(new Dimension(width, height));
		center.setMinimumSize(new Dimension(width, height));
		center.setPreferredSize(new Dimension(width, height));

		container.add(toolbar, BorderLayout.NORTH);
		container.add(center, BorderLayout.CENTER);
		container.add(status, BorderLayout.SOUTH);

		bar = new DevToolBar(toolbar);
		setJMenuBar(bar);
		bar.setClientManager(clientManager);
		serial.setClientManager(clientManager);
		sms.setClientManager(clientManager);

		pack();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		try {
			clientManager.setup();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String getNumber() {
		return sms.getNumber();
	}

	public String getMessage() {
		return sms.getMessage();
	}

	public String getPort() {
		return serial.getPort();
	}

	public void setPort(String port) {
		serial.setPort(port);
	}

	public void setPorts(List<String> ports) {
		serial.setPorts(ports);
	}

	public String getURL() {
		return url.getURL();
	}

	public void setURL(String address) {
		url.setURL(address);
	}

	public void setStatus(String msg) {
		status.setStatus(msg);
	}

}
